public class Solution {
    public int evalRPN(String[] tokens) {
        LinkedList<Integer> nums = new LinkedList<>();
        for(String token : tokens) {
            if(token.matches("^-?\\d+")) {
                nums.push(Integer.valueOf(token));
            } else {
                int second = nums.poll();
                int first = nums.poll();
                switch(token) {
                    case "+":
                        nums.push(first + second);
                        break;
                    case "-":
                        nums.push(first - second);
                        break;
                    case "*":
                        nums.push(first * second);
                        break;
                    case "/":
                        nums.push(first / second);
                        break;
                }
            }
        }
        return nums.peek();
    }
}